package com.idroc.coelacanth.core.membership;

import org.jboss.netty.buffer.ChannelBuffer;

import com.idroc.coelacanth.core.message.AbstractMessage;

/**
 * 心跳状态失效查询消息
 * @author yuyoo (yuyoo4j@163.com)
 * @date 2009-12-7 上午09:37:53
 */
public class HeartbeatInvalidRequestMessage extends AbstractMessage {
	
	/**
	 * 请求来源节点
	 */
	private  Endpoint from = null;
	
	/**
	 * 心跳版本
	 */
	private  long pulseVersion = -1;
	
	/**
	 * 心跳时间
	 */
	private  long pulseTime = -1;
	
	/**
	 * 心跳有效期
	 */
	private  long lifecycle = -1;
	
	

	@Override
	public void decode(ChannelBuffer ib) { 

		from = new Endpoint();
		from.setHost(decodeString(ib));
		from.setPort(ib.readInt());
		pulseVersion = ib.readLong();
		pulseTime = ib.readLong();
		lifecycle = ib.readLong();
	}

	@Override
	public void encode(ChannelBuffer ob) {

		encodeString(ob, from.getHost());
		ob.writeInt(from.getPort());
		ob.writeLong(pulseVersion);
		ob.writeLong(pulseTime);
		ob.writeLong(lifecycle);
	}

	public Endpoint getFrom() {
		return from;
	}

	public void setFrom(Endpoint from) {
		this.from = from;
	}

	public long getPulseVersion() {
		return pulseVersion;
	}

	public void setPulseVersion(long pulseVersion) {
		this.pulseVersion = pulseVersion;
	}

	public long getPulseTime() {
		return pulseTime;
	}

	public void setPulseTime(long pulseTime) {
		this.pulseTime = pulseTime;
	}

	public long getLifecycle() {
		return lifecycle;
	}

	public void setLifecycle(long lifecycle) {
		this.lifecycle = lifecycle;
	}
 
	@Override
	public String toString() {
	
		StringBuilder sb = new StringBuilder();
		sb.append("HeartbeatInvalidRequestMessage[");
		sb.append("sn:").append(this.getSN()).append(",");
		sb.append("from:").append(from).append(",");
		sb.append("pulseVersion:").append(pulseVersion).append(",");
		sb.append("pulseTime:").append(pulseTime).append(",");
		sb.append("lifecycle:").append(lifecycle); 
		sb.append("]");
		return sb.toString();
	}
}
